package com.mg.unpack.aio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 伪异步—通过服务端线程池的方式实现
 */
public class TimeServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = null;
        try {
            int port = 8088;
            serverSocket = new ServerSocket(port);

            TimeServerHandlerExecutePool executePool = new TimeServerHandlerExecutePool(50, 1000);
            while (true) {
                Socket socket = serverSocket.accept();
                executePool.execute(new TimeServerHandler(socket));
            }
        } finally {
            if (serverSocket != null) {
                serverSocket.close();
                serverSocket = null;
            }
        }
    }
}